package innerclassdemo;

/**
 * @Author 12629
 * @Description：
 */
/*class OuterClass {
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;

    *//**
     * 实例内部类：
     * 1、不能定义静态的属性或者方法
     * 2、实例内部类当中 包含了外部类的this
     * 3、获取实例内部类的对象
     * 4、生成的字节码文件：外部类$内部类
     *//*
    class InnerClass {
        public int data1 = 1111;
        public int data4 = 4;
        private int data5 = 5;
        public static final int data6 = 6;

        public InnerClass() {
            System.out.println("InnerClass::init()");
        }

        public void test() {
            System.out.println(this.data1);
            System.out.println(OuterClass.this.data1);
        }
    }


    public void func() {
        System.out.println("OuterClass::func()");
    }

}*/
class OuterClass {
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;

    /**
     * 静态内部类：
     * 1、如何拿到静态内部类的对象？
     *  OuterClass.InnerClass innerClass = new OuterClass.InnerClass();
     * 2、不能在静态内部类当中，直接访问外部类非静态的数据成员
     *
     */
    static class InnerClass {
        public int data4 = 4;
        private int data5 = 5;
        public static int data6 = 6;
        public OuterClass outer;

        public InnerClass() {

        }

        public InnerClass(OuterClass outerClass) {
            System.out.println("静态内部类的构造方法!");
            this.outer = outerClass;
        }

        public void test() {
            System.out.println("test方法执行了！");
            /*OuterClass outerClass = new OuterClass();
            System.out.println(outerClass.data1);
            System.out.println(outerClass.data2);*/

            System.out.println(outer.data1);
            System.out.println(outer.data2);

            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
        public static void test2() {
            System.out.println("test2");
        }
    }

}
class Person {
    public String name;
    public int age;

    public void test() {
        System.out.println("gaobo!");
    }

    /*public void show() {
        System.out.println("姓名："+name +" 年龄："+age);
    }*/

    //当我自己重新实现了这个toString方法之后，编译器就会调用我自己实现的这个toString方法
    @Override//注解：注释+解释【代表这个方法是重写父类的】
    public String toString() {
        return "姓名："+name +" 年龄："+age;
    }
}

public class Test {

    public static void main(String[] args) {
        Person person = new Person();
        /*String ret = person.toString();
        System.out.println(ret);*/
        System.out.println(person);

    }

    public static void main4(String[] args) {
        new Person(){
            //匿名内部类：接口-》多线程
            @Override
            public void test() {
                System.out.println("hhhh，不是你！");
            }
        }.test();
    }

    public static void func() {
        class A {
            public void test() {
                System.out.println(10);
            }
        }
        A a = new A();
        a.test();
    }

    public static void main3(String[] args) {
        //func();
        new Person().test();//匿名对象,只能使用一次
        System.out.println(new Person().name);

        Person person = new Person();
        person.test();
        System.out.println(person.name);
    }

    public static void main2(String[] args) {
        OuterClass.InnerClass innerClass = new OuterClass.InnerClass();
        innerClass.test();
    }

    public static void main1(String[] args) {
       /* OuterClass outerClass = new OuterClass();
        OuterClass.InnerClass innerClass = outerClass.new InnerClass();
        innerClass.test();*/
    }
}
